//
//  LGDiscover.m
//  lgdw
//
//  Created by Apple on 15/12/8.
//  Copyright © 2015年 Apple. All rights reserved.
//

#import "LGDiscover.h"
#import "LGNetworkTools.h"
@implementation LGDiscover

+ (instancetype)discoverWithDict:(NSDictionary *)dict {
    LGDiscover *discover = [[self alloc] init];
    
    [discover setValuesForKeysWithDictionary:dict];
    
    return discover;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key{
    
}

+ (void)DiscoverListWithSuccessBlock:(void (^)(NSArray *))successBlock errorBlock:(void (^)(NSError *))errorBlock {
    
    NSDictionary *parameter =
    // 未登录获取的数据
//    @{@"Appid":@"10000024",
//      @"Appkey":@"e93b6295c8143f2805c2c3013390d344",
//      @"act":@"lists",
//      @"client_ver":@"1.2.1",
//      @"mid":@"0feab903c30b8d91f8ba9d46c153e1de93c2055e",
//      @"page":@"0",
//      @"platform":@"iPhone9.1",
//      @"yd_auth":@"",
//      @"yd_key":@"",
//      @"yd_uid":@""};
    // 登陆
    @{@"Appid":@"10000024",
      @"Appkey":@"e93b6295c8143f2805c2c3013390d344",
      @"act":@"lists",
      @"client_ver":@"1.2.1",
      @"mid":@"e553e2d24021fb8a156296b27e95fe3e4cf40791",
      @"page":@"0",
      @"platform":@"iPhone9.1",
      @"yd_auth":@"d4f6ZD7td1cA6eH0SFATxSF07DKOXB%2B7gHKhfLtmV8FYgoK%2BUm4Wp%2FCaZti6tWV75B%2FtEtCn12jixPPuZvdHoYAe%2FFntpIYn2dLpN89taV3K1vhT3Q%2BBDBixLRwmKZwel%2BXn",
      @"yd_key":@"9563klroXuyAUEc61OJWViLHGR%2BCzHgbhYmyhwkZYSJ3",
      @"yd_uid":@"7014"};
    [[LGNetworkTools sharedManager] POST:@"/discover" parameters:parameter success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *responseObject) {
        NSArray *array = responseObject[@"data"];
        
        // 字典转模型
        NSMutableArray *mArray = [NSMutableArray arrayWithCapacity:10];
        [array enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            LGDiscover *discover = [LGDiscover discoverWithDict:obj];
            [mArray addObject:discover];
        }];
        
        if (successBlock) {
            successBlock(mArray.copy);
        }
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (errorBlock) {
            NSLog(@"LGDiscover错误%@",error);
            
        }
    }];
    
    
    
    
    
    
    
    
    
    //    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    //
    //    NSString *urlStr = @"http://api.duwu.me/discover";
    //
    //    NSDictionary *parameter =
    //    @{@"Appid":@"10000024",
    //      @"Appkey":@"e93b6295c8143f2805c2c3013390d344",
    //      @"act":@"lists",
    //      @"client_ver":@"1.2.1",
    //      @"mid":@"0feab903c30b8d91f8ba9d46c153e1de93c2055e",
    //      @"page":@"0",
    //      @"platform":@"iPhone9.1",
    //      @"yd_auth":@"",
    //      @"yd_key":@"",
    //      @"yd_uid":@""};
    //
    //    // 添加解析格式
    //    manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
    //
    //    // 发送 post 请求
    //    [manager POST:urlStr parameters:parameter success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
    //        NSArray *arr = responseObject[@"data"];
    //
    //        NSLog(@"%@",arr);
    //    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
    //        NSLog(@"error: %@",error);
    //    }];
    
    
}
@end
